package org.jadapter.tests.spring;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jadapter.registry.TransformerRegistry;
import org.jadapter.tests.examples.Csv;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestSpring25Support {

    @Test
    public void shouldWorkWithAutowire() {

        ApplicationContext ctx = new ClassPathXmlApplicationContext(
                "org/jadapter/tests/spring/context-2.5.xml");

        TransformerRegistry adapters = (TransformerRegistry) ctx.getBean("adapters");
        List<String> list = Arrays.asList("Foo", "Bar");

        assertEquals("Foo,Bar", adapters.transform(list, Csv.class).csv());

    }

    @Test
    public void shouldWorkWithAutoConfigure() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext(
                "org/jadapter/tests/spring/context-2.5.xml");

        TransformerRegistry adapters = (TransformerRegistry) ctx.getBean("adapters");
        Map<String,String> map = new HashMap<String,String>();
        map.put("foo", "bar");

        assertEquals("foo:bar", adapters.transform(map, Csv.class).csv());
    }

}
